package protocol;


import java.util.logging.FileHandler;
import java.util.logging.Logger;

public class ForumLogger {
	
	private Logger infoLogger;
	private Logger warningLogger;
	private static ForumLogger instance = null;
	
	private ForumLogger()
	{
		try
		{
		FileHandler infoFileHandler = new FileHandler("Log/infoLog.txt");
		
		FileHandler warningFileHandler = new FileHandler("Log/warningLog.txt");
		
		infoLogger = Logger.getLogger("InfoLogger");
		infoLogger.addHandler(infoFileHandler);
		
		warningLogger = Logger.getLogger("warningLogger");
		warningLogger.addHandler(warningFileHandler);
		
		infoLogger.info("INFO Logger Is Activated");
		warningLogger.info("WARNING Logger Is Activated");
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
	}
	
	public synchronized void infoMsg(String ID, String loggerInfoMsg)
	{
		try
		{
			if(ID != null)
				infoLogger.info("User " + ID + " :"+ loggerInfoMsg);
			else
				infoLogger.info("Guest :" + loggerInfoMsg);
		}
		catch(Exception e)
		{
			System.out.println("info massage exception");
		}
	}
	
	public synchronized void warningMsg(String ID, String loggerInfoMsg)
	{
		try
		{
			if(ID != null)
				warningLogger.warning("User " + ID + " :" +loggerInfoMsg);
			else
				warningLogger.info("Guest :" + loggerInfoMsg);
		}
		catch(Exception e)
		{
			System.out.println("warning massage exception");
		}
	}
	
	public static ForumLogger getInstance()
	{
		if(instance == null) instance = new ForumLogger();
		return instance;
	}

}
